package com.example.administrator.readbook.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.view.LayoutInflater;

import com.example.administrator.readbook.R;
import com.example.administrator.readbook.bean.BookSourceBean;

import java.util.List;

/**
 * Created by Administrator on 2018/7/3.
 */

public class AdapterBookSourceList extends BaseAdapter {
    private Context context;
    private List<BookSourceBean> bookSourceList;

    public AdapterBookSourceList(Context context, List<BookSourceBean> bookSourceList) {
        this.context = context;
        this.bookSourceList = bookSourceList;
    }

    @Override
    public int getCount() {
        return bookSourceList.size();
    }

    @Override
    public Object getItem(int position) {
        return bookSourceList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        BookSourceBean bookSourceBean = bookSourceList.get(position);
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_booksource, null);
            viewHolder = new ViewHolder();
            viewHolder.titleTv = convertView.findViewById(R.id.adapter_booksource_name);
            viewHolder.lastChapterTv = convertView.findViewById(R.id.adapter_booksource_lastchapter);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.titleTv.setText(bookSourceBean.getName());
        viewHolder.lastChapterTv.setText(bookSourceBean.getLastChapter());
        return convertView;
    }

    class ViewHolder {
        TextView titleTv, lastChapterTv;
    }
}
